home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / ROM_Kernel_Manuals / Devices / dev_examples / Read_Potinp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-20  |  2.0 KB  |  83 lines

  1. /*
  2.  * Read_Potinp.c
  3.  *
  4.  * An example of using the potgo.resource to read pins 9 and 5 of
  5.  * port 1 (the non-mouse port).  This bypasses the gameport.device.
  6.  * When the right or middle button on a mouse plugged into port 1 is pressed,
  7.  * the read value will change.
  8.  *
  9.  * Use of port 0 (mouse) is unaffected.
  10.  *
  11.  * Compile with SAS C 5.10  lc -b1 -cfistq -v -y -L
  12.  *
  13.  * Run from CLI only
  14.  */
  15.  
  16. #include <exec/types.h>
  17. #include <exec/memory.h>
  18. #include <dos/dos.h>
  19. #include <resources/potgo.h>
  20. #include <hardware/custom.h>
  21.  
  22. #include <clib/exec_protos.h>
  23. #include <clib/potgo_protos.h>
  24.  
  25. #include <stdio.h>
  26.  
  27. #ifdef LATTICE
  28. int CXBRK(void) {return(0);}  /* Disable SAS Ctrl-C checking */
  29. int chkabort(void) { return(0); }  /* really */
  30. #endif
  31.  
  32. struct PotgoBase *PotgoBase;
  33. ULONG potbits;
  34. UWORD value;
  35.  
  36. #define UNLESS(x) if(!(x))
  37. #define UNTIL(x)  while(!(x))
  38.  
  39. #define OUTRY 1L<<15
  40. #define DATRY 1L<<14
  41. #define OUTRX 1L<<13
  42. #define DATRX 1L<<12
  43.  
  44. extern struct Custom far custom;
  45.  
  46. void main(int argc,char **argv)
  47. {
  48. UNLESS (PotgoBase=(struct PotgoBase *)OpenResource("potgo.resource"))
  49.         return;
  50.  
  51. potbits=AllocPotBits(OUTRY|DATRY|OUTRX|DATRX);
  52.  
  53. /* Get the bits for the right and middle mouse buttons on the alternate mouse port. */
  54.  
  55. if (potbits != (OUTRY|DATRY|OUTRX|DATRX))
  56.     {
  57.     printf("Pot bits are already allocated! %lx\n",potbits);
  58.     FreePotBits(potbits);
  59.     return;
  60.     }
  61.  
  62. /* Set all ones in the register (masked by potbits) */
  63. WritePotgo(0xFFFFFFFFL,potbits);
  64.  
  65. printf("\nPlug a mouse into the second port.  This program will indicate when\n");
  66. printf("the right or middle button (if the mouse is so equipped) is pressed.\n");
  67. printf("Stop the program with Control-C. Press return now to begin.\n");
  68.  
  69. getchar();
  70.  
  71. UNTIL (SIGBREAKF_CTRL_C & SetSignal(0L,0L))
  72.       /* until CTRL-C is pressed */
  73.       {
  74.       /* Read word at $DFF016 */
  75.         value = custom.potinp;
  76.  
  77.       /* Show what was read (restricted to our allocated bits) */
  78.       printf("POTINP = $%lx\n",value & potbits);
  79.       }
  80.  
  81. FreePotBits(potbits);
  82. }
  83.